﻿using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Learn.Net8.Extension.ServiceExtensions
{
    public static class AllOptionRegister
    {
        /// <summary>
        /// 注册所有选项配置
        /// </summary>
        /// <param name="services">主服务</param>
        /// <exception cref="ArgumentNullException"></exception>
        public static void AddAllOptionRegister(this IServiceCollection services)
        {
            // 检查服务集合是否为空
            if (services == null) throw new ArgumentNullException(nameof(services));

            // 获取所有实现 IConfigurableOptions 接口的类型，并注册
            foreach (var optionType in typeof(ConfigurableOptions).Assembly.GetTypes().Where(s =>
                         !s.IsInterface && typeof(IConfigurableOptions).IsAssignableFrom(s)))
            {
                services.AddConfigurableOptions(optionType);
            }
        }
    }
}
